layui.config({
    base: '/static/layui/' //静态资源所在路径
}).extend({
    index: 'index' //主入口模块
}).use(['index', 'user'], function () {
    let $ = layui.$
        , setter = layui.setter
        , admin = layui.admin
        , form = layui.form;
    form.render();
    $("#verCode").on('click', function () {
        $(this).attr("src", "/sys/utils/verifyCode?" + Math.random());
    });
    //提交
    form.on('submit(loginBtn)', function (obj) {
        //请求登入接口
        $.post({
            url: '/toLogin'
            , data: obj.field
            ,type: 'post'
            ,success: function (res) {
                if (res.code == 200){
                    //登入成功的提示与跳转
                    layer.msg('登入成功', {
                         icon: 1
                        , time: 1000
                    }, function () {
                        location.href = '/index'; //后台主页
                    });
                }else{
                    layer.msg(res.msg, {icon: 5});
                }
            }
        });
    });
    $(document).keyup(function(event) {
        if (event.keyCode == 13) {
            $("#loginBtn").trigger("click");
        }
    })
});